package com.maxatime.service.impl;

import com.maxatime.dao.CurriculumMapper;
import com.maxatime.dao.TrimesterCurriculumScheduleMapper;
import com.maxatime.exception.PhoenixException;
import com.maxatime.pojo.*;
import com.maxatime.service.CurriculumService;
import com.maxatime.utils.SerialNumberUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.List;

/**
 * @author Mr.Zhao
 * @title:
 * @projectName phoenix
 * @description: TODO
 * @date 2021/8/26 19:19
 */
@Service
public class CurriculumServiceImpl implements CurriculumService {
    Logger log= LogManager.getLogger();
    @Autowired
    private CurriculumMapper curriculumMapper;
    @Autowired
    private TrimesterCurriculumScheduleMapper trimesterCurriculumScheduleMapper;


    @Override
    public List<Curriculum> curriculumFind(CurriculumVo vo) {

        return curriculumMapper.curriculumFind(vo);
    }

    @Override
    public Integer curriculumDelete(int pkId) {
        return curriculumMapper.curriculumDelete(pkId);
    }

    @Override
    public List<Curriculum> curriculumFindd() {
        return curriculumMapper.curriculumFindd();
    }

    @Override
    public Integer updatecurr(Curriculum curriculum) throws PhoenixException {
        try {
            return curriculumMapper.updateByPrimaryKeySelective(curriculum);
        }catch (Exception e){
            log.error("dormitoryMapper.updateByPrimaryKeySelective:::"+curriculum);
            log.error("dormitoryMapper.updateByPrimaryKeySelective:::"+e.getMessage());
            throw new PhoenixException("9999","修改失败");
        }
    }

    @Override
    public Integer insertCurriculum(Curriculum curriculum) throws PhoenixException {
        try {

//            String dd= SerialNumberUtil.getUUID();
            String curriculumTeacherId=System.currentTimeMillis()+"";

            Calendar now = Calendar.getInstance();//获取时间
            curriculum.setUpdateTime(now.getTime());//当前时间
            curriculum.setCreateTime(now.getTime());
            curriculum.setDeleteFlag("0");
            curriculum.setCurriculumTeacherId(curriculumTeacherId);

            return curriculumMapper.insert(curriculum);
        }catch (Exception e){
            log.error("dormitoryMapper.updateByPrimaryKeySelective:::"+curriculum);
            log.error("dormitoryMapper.updateByPrimaryKeySelective:::"+e.getMessage());
            throw new PhoenixException("9999","修改失败");
        }
    }

    @Override
    public Integer deleteListCurr(List<Integer> list) {
        return curriculumMapper.deleteListCurr(list);
    }

    @Override
    public List<TrimesterCurriculumSchedule> getcourse() {
        return trimesterCurriculumScheduleMapper.getcourse();
    }


}
